package com.isoftstone.industry.aaa.core.service.accounting.charging.impl;

import com.isoftstone.industry.common.context.BeanFactory;
import com.isoftstone.industry.persistance.bean.BillingCycle;
import com.isoftstone.industry.persistance.bean.ChargingItemDetail;
import com.isoftstone.industry.persistance.bean.PricingInfo;
import com.isoftstone.industry.persistance.bean.User;
import com.isoftstone.industry.aaa.core.service.accounting.charging.IChargingEngine;

public class ChargingEnginerBuilder
{
	public static IChargingEngine build(String mode, User user, BillingCycle billingCycle, ChargingItemDetail chargingItemDetail)
	{
		IChargingEngine result = null;
		if (PricingInfo.ITariffTypes.NONRECURRING.equalsIgnoreCase(mode)) //一次性计费
		{
			NonRecurringChargingEngine enginer = (NonRecurringChargingEngine) BeanFactory.getInstance().getBeanByName("nonRecurringChargingEngine");
			enginer.initialize(user, billingCycle, chargingItemDetail);
			result = enginer;
		} else if (PricingInfo.ITariffTypes.PERIODIC.equalsIgnoreCase(mode)) //周期性计费
		{
			PeriodicChargingEngine enginer = (PeriodicChargingEngine) BeanFactory.getInstance().getBeanByName("periodicChargingEngine");
			enginer.initialize(user, billingCycle, chargingItemDetail);
			result = enginer;
		} else if (PricingInfo.ITariffTypes.USAGE.equalsIgnoreCase(mode)) //使用量计费	
		{
			UsageChargingEngine enginer = (UsageChargingEngine) BeanFactory.getInstance().getBeanByName("usageChargingEngine");
			enginer.initialize(user, billingCycle, chargingItemDetail);
			result = enginer;
		} else
		{
			throw new UnsupportedOperationException("非法的计费模式！");
		}
		return result;
	}
}
